<?php

namespace app\admin\model;

use think\Model;

class UserList extends Model
{
    protected $autoWriteTimestamp = true;

    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        if (input('get.sign')) $where[] = ['sign', 'like', "%" . input('get.sign') . "%"];
        if (input('get.device_id')) $where[] = ['device_id', 'like', "%" . input('get.device_id') . "%"];
        if (input('get.name')) $where[] = ['name', 'like', "%" . input('get.name') . "%"];
        if (input('get.status')) $where[] = ['status', '=', input('get.status') - 1];
        $list = self::order('id', 'desc')
            ->where($where)
            ->paginate($limit);
        return ['code' => 0, 'data' => $list->items(), 'extend' => ['count' => $list->total(), 'limit' => $limit]];
    }

    public static function getAll()
    {
        return self::order('id', 'desc')
            ->field('id,name')
            ->select()
            ->toArray();
    }
}